/*
 * Copyright (c) 2006-2020, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2020-09-02     RT-Thread    first version
 */

#include <rtthread.h>
#include <rtdevice.h>
#include <onenet.h>
#include "drv_common.h"
#include "pms7003.h"
//#include "oled.h"
#define LED_PIN GET_PIN(I, 8)
#define THREAD_PRIORITY         25
#define THREAD_STACK_SIZE       512
#define THREAD_TIMESLICE        5
//static rt_thread_t tid1 = RT_NULL;
ALIGN(RT_ALIGN_SIZE)
//static char thread2_stack[1024];
//static struct rt_thread thread2;

#define LED_PIN GET_PIN(I, 8)

extern void wlan_autoconnect_init(void);

int main(void)
{
    PMS_Serial_init();  //串口设备初始化;
    rt_pin_mode(LED_PIN, PIN_MODE_OUTPUT);
    wlan_autoconnect_init(); //初始化WiFi自动重连
    rt_wlan_config_autoreconnect(RT_TRUE); //在WLAN设备上启用自动重新连接
    onenet_mqtt_init(); //初始化Onenet MQTT功能;
    PMS_Read();

    while (1)
    {
        rt_thread_mdelay(1000);
        rt_pin_write(LED_PIN, PIN_HIGH);
//        Temp = rand() % 100;
        onenet_mqtt_upload_digit("PM1_0", PMS_Sensor.Air_PM1_0); //PM1.0浓度值上传
        onenet_mqtt_upload_digit("PM2_5", PMS_Sensor.Air_PM2_5);
        onenet_mqtt_upload_digit("Quantity_2_5", PMS_Sensor.Quan_2_5);//0.1L空气中2.5um颗粒物数量
        rt_thread_mdelay(1000);
        rt_pin_write(LED_PIN, PIN_LOW);
    }
    return RT_EOK;
}

#include "stm32h7xx.h"
static int vtor_config(void)
{
    /* Vector Table Relocation in Internal QSPI_FLASH */
    SCB->VTOR = QSPI_BASE;
    return 0;
}
INIT_BOARD_EXPORT(vtor_config);

